import 'package:get_storage/get_storage.dart';
import 'package:hixing_app/extensions/str_ext.dart';
import 'package:hixing_app/utils/storage/sharedpre_storage.dart';

class GetUserStorage {
// 缓存模块的key
  static const _storageBoxKey = "app_user_storage_container";
  static final GetStorage _userStorage = GetStorage(_storageBoxKey);

  static GetStorage get userStorage => _userStorage;

  static init() {
    GetStorage.init(_storageBoxKey);
  }


  // token
  static const String userTokenKey = "userToken";

  String? get token => _userStorage.read<String>(userTokenKey);

  Future<void> setToken(String val) async {
    await _userStorage.write(userTokenKey, val);
  }

  Future<void> removeToken() async {
    await remove(userTokenKey);
  }


  // lastAccount 记住上一次登录的账号
  static const String lastAccountKey = "lastAccount";

  String? get lastAccount => _userStorage.read<String>(lastAccountKey);

  Future<void> setLastAccount(String val) async {
    await _userStorage.write(lastAccountKey, val);
  }

  Future<void> removeLastAccount() async {
    await remove(lastAccountKey);
  }


  Future<void> remove(String key) async {
    await _userStorage.remove(key);
  }

  Future<void> removeAll() async {
    _userStorage.erase();
  }
}
